package com.cqie.controller.entrepot;

import com.cqie.dto.entrepot.AddEntrepotWarehouseInfoDto;
import com.cqie.entity.EntrepotWarehouseInfo;
import com.cqie.exception.SpecialException;
import com.cqie.service.IEntrepotWarehouseInfoService;
import com.cqie.util.ResultTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 不吃海鲜
 * @since 2024-12-05
 */

@Tag(name = "仓库信息Controller", description = "描述：仓库信息接口")
@RestController
@RequestMapping({"/api/v1.0/entrepotWarehouseInfo", "/api/v1/entrepotWarehouseInfo"})
public class EntrepotWarehouseInfoController {

    private final IEntrepotWarehouseInfoService entrepotWarehouseInfoService;

    public EntrepotWarehouseInfoController(IEntrepotWarehouseInfoService entrepotWarehouseInfoService) {
        this.entrepotWarehouseInfoService = entrepotWarehouseInfoService;
    }

    @Operation(summary = "新增仓库信息")
    @PostMapping("/addWarehouseInfo")
        public ResultTemplate<Boolean> addWarehouseInfo(@RequestBody AddEntrepotWarehouseInfoDto addEntrepotWarehouseInfoDto) throws SpecialException {
        return ResultTemplate.Success(entrepotWarehouseInfoService.addWarehouseInfo(addEntrepotWarehouseInfoDto));
    }

    @Operation(summary = "查询仓库List")
    @GetMapping("/getWarehouseInfoList")
    public ResultTemplate<List<EntrepotWarehouseInfo>> getWarehouseInfoList(
            @RequestParam(required = false) String likeQuery,
            @RequestParam(defaultValue = "0", required = false) String state,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(defaultValue = "1", required = false) Integer pageIndex) throws SpecialException {
        return ResultTemplate.Success(entrepotWarehouseInfoService.getWarehouseInfoList(likeQuery , state,  pageSize ,
                pageIndex));
    }

    @Operation(summary = "查询仓库信息")
    @GetMapping("/getWarehouseInfo")
    public ResultTemplate<EntrepotWarehouseInfo> getWarehouseInfo(@RequestParam Integer warehouseId) throws SpecialException {
        return ResultTemplate.Success(entrepotWarehouseInfoService.getById(warehouseId));
    }

    @Operation(summary = "删除仓库信息")
    @GetMapping("/delWarehouseInfo")
    public ResultTemplate<Boolean> delWarehouseInfo(@RequestParam Integer warehouseId) throws SpecialException {
        return ResultTemplate.Success(entrepotWarehouseInfoService.delWarehouseInfo(warehouseId));
    }

    @Operation(summary = "计算仓库数量")
    @GetMapping("/getWarehouseInfoCount")
    public ResultTemplate<Long> getWarehouseInfoCount(){
        return ResultTemplate.Success(entrepotWarehouseInfoService.getWarehouseInfoCount());
    }

}
